// 视频投射
class VideoCast {
    constructor() {
        var scene
        var viewer
        var entitie
    }
    // 投射到墙上
    addWall() {
        if (this.entitie) {
            this.viewer.entities.remove(entitie)
        }
        var videoElement = document.getElementById('trailer')
        entitie = this.viewer.entities.add({
            position: Cesium.Cartesian3.fromDegrees(118.9411658832441, 31.35783183124998, 75),
            plane: {
                plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_Y, 0.0),
                dimensions: new Cesium.Cartesian2(-100.0, 90.0),
                material: videoElement,
            },
        })
    }
    // 投射到地球上
    addEllipsoid() {
        if (entitie) {
            viewer.entities.remove(entitie)
        }
        var videoElement = document.getElementById('trailer')
        entitie = viewer.entities.add({
            position: Cesium.Cartesian3.fromDegrees(118.9408658832441, 31.35783183124998, 75),
            ellipsoid: {
                radii: new Cesium.Cartesian3(50, 50, 50),
                material: videoElement,
            },
        })
    },
    createMap() {
        Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIwMzYzM2JiMi1mZDg0LTRmZmEtODYzNy02YjA2NDZmMmU5YTYiLCJpZCI6MjU5LCJhc3NldHMiOnsiMSI6eyJ0eXBlIjoiVEVSUkFJTiIsImV4dGVuc2lvbnMiOlt0cnVlLHRydWUsdHJ1ZV0sInB1bGxBcGFydFRlcnJhaW4iOmZhbHNlfX0sInNyYyI6ImQ2ZjQ1N2I2LTIxZTQtNDg4Ni05MjhkLTVhM2QyMGY4YmI1YiIsImlhdCI6MTYzNzgzMDg5MSwiZXhwIjoxNjM3ODM0NDkxfQ.bOsm3KagdsGeVlEyzX674qcehlsOpyRzKzdRFq7wzGM'
        let cesiumTerrainProvider = new Cesium.CesiumTerrainProvider({
            url: 'http://localhost:8080/cesiumSample/data/gaochunTerrain',
        })

        viewer = new Cesium.Viewer('cesiumContainer', {
            selectionIndicator: false,
            terrainProvider: cesiumTerrainProvider,
            contextOptions: {
                webgl: {
                    alpha: true,
                    depth: true,
                    stencil: false,
                    antialias: true,
                },
            },
            animation: false, //是否显示动画控件
            baseLayerPicker: false, //是否显示图层选择控件
            geocoder: false, //是否显示地名查找控件
            timeline: false, //是否显示时间线控件
            sceneModePicker: false, //是否显示投影方式控件
            navigationHelpButton: false, //是否显示帮助信息控件
            infoBox: false, //是否显示点击要素之后显示的信息
            imageryProvider: false,
            fullscreenButton: false,
        })

        viewer.scene.globe.depthTestAgainstTerrain = false
        viewer.scene.primitives.destroyPrimitives = false
    }
    addLayer() {
        var imageryLayers = viewer.imageryLayers
        scene = viewer.scene

        //天地图影像图层
        tiandituImageLayer = new Cesium.ImageryLayer(
            new Cesium.WebMapTileServiceImageryProvider({
                url: 'http://{s}.tianditu.gov.cn/img_c/wmts?service=wmts&request=GetTile&version=1.0.0' + '&LAYER=img&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}' + '&style=default&format=tiles&tk=440b96d736fad95da7934bc130a2258a',
                layer: 'tdtImg_c',
                style: 'default',
                format: 'tiles',
                tileMatrixSetID: 'c',
                subdomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
                tilingScheme: new Cesium.GeographicTilingScheme(),
                tileMatrixLabels: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],
                maximumLevel: 18,
            })
        )
        viewer.imageryLayers.add(tiandituImageLayer)

        viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(118.9401658832441, 31.35783183124998, 826.0458), //设置位置
            orientation: {
                heading: Cesium.Math.toRadians(0),
                pitch: Cesium.Math.toRadians(-90),
                roll: 0,
            },
        })

        // 亮度设置
        var stages = viewer.scene.postProcessStages
        viewer.scene.brightness = viewer.scene.brightness || stages.add(Cesium.PostProcessStageLibrary.createBrightnessStage())
        viewer.scene.brightness.enabled = true
        viewer.scene.brightness.uniforms.brightness = Number(1.5)
    }
}